package ${package}.dao.base;

import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;

public class GeneralWriteDao extends SqlSessionDaoSupport {
	
	private SqlSession sqlSessionW;
	
	private SqlSession sqlSessionWBatch;

	@Autowired
	private SqlSessionFactory sqlSessionFactoryW;

	/**
	 * @author QXX
	 * @date 2014年10月13日 下午1:52:53
	 * @Description: 写操作数据库使用 
	 * @return
	 * @throws
	 */
	public SqlSession getSqlSessionW() {
		if (this.sqlSessionW == null) {
			synchronized (this) {
				sqlSessionW = new SqlSessionTemplate(this.sqlSessionFactoryW);
			}
		}
		return this.sqlSessionW;
	}
	
	/**
	 * @author QXX
	 * @date 2014年10月13日 下午1:52:00
	 * @Description: 批量写操作数据库使用，非批量勿用 
	 * @return
	 * @throws
	 */
	public SqlSession getSqlSessionWBatch() {
		if (this.sqlSessionWBatch == null) {
			synchronized (this) {
				sqlSessionFactoryW.openSession(ExecutorType.BATCH, true);
				sqlSessionWBatch = new SqlSessionTemplate(this.sqlSessionFactoryW);
			}
		}
		return this.sqlSessionWBatch;
	}
}
